package com.atguigu.spzx.pay.controller;

import com.alipay.api.AlipayApiException;
import com.alipay.api.internal.util.AlipaySignature;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.atguigu.spzx.pay.service.AlipayService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * ClassName: AlipayController
 * Package: com.atguigu.spzx.pay.controller
 * Description:
 *
 * @Author 刘强
 * @Create 2024/7/19 18:06
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/order/alipay")
public class AlipayController {
    @Resource
    private AlipayService alipayService;

    /**
     * 去支付  -> 返回一个支付宝的支付页面  -> 表单字符串
     * @param orderNo
     * @return
     */
    @GetMapping("submitAlipay/{orderNo}")
    public Result<String> submitAlipay(@PathVariable String orderNo){
        String formStr = alipayService.submitAlipay(orderNo);
        return Result.build(formStr, ResultCodeEnum.SUCCESS);
    }

    /**.
     * 支付的异步回调接口
     * @return
     */
    @PostMapping("callback/notify")
    public String callback(@RequestParam Map<String, String> paramMap, HttpServletRequest request){
     return  alipayService.callback(paramMap,request);
    }
}
